package ass.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ass.beans.CinemaBean;
import ass.beans.MovieBean;
import ass.dao.MovieDAO;
import ass.dao.support.CinemaDAOImpl;
import ass.dao.support.MovieDAOImpl;

/**
 * Servlet implementation class searchMovieServlet
 */
public class searchMovieServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public searchMovieServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// MovieDAOImpl movieDAOImpl = new MovieDAOImpl();
		// MovieBean movieResult = movieDAOImpl.getMovieByTitle((String) request
		// .getParameter("title"));
		//
		// System.out.println(movieResult.getMovie_title());
	
		
		String title = (String) request.getParameter("title");
		String actor = (String) request.getParameter("actor");
		String genre = (String) request.getParameter("genre");
		String yearfrom = (String) request.getParameter("yearfrom");
		String yearto = (String) request.getParameter("yearto");

		System.out.println(title);
		System.out.println(actor);
		System.out.println(genre);
		System.out.println(yearfrom);
		System.out.println(yearto);
		
		MovieDAO movieDAO = new MovieDAOImpl();
		List<MovieBean> movieBeanList = new ArrayList<MovieBean>();
		movieBeanList = movieDAO.getMovie(title, actor, genre, yearfrom, yearto);

		String nextJSP = "/userSearchResult.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(nextJSP);
		request.setAttribute("movieBeanList", movieBeanList);
		dispatcher.forward(request, response);

		// response.setContentType("text/html");// from response, set content
		// type
		// PrintWriter out = response.getWriter();// from response, get output
		// // writer
		// out.write(movieResult.getMovie_title()
		// + movieResult.getMovie_showing_time());
		// out.close();

		// }else {
		// // String nextJSP = "/register.jsp";
		// // RequestDispatcher dispatcher =
		// getServletContext().getRequestDispatcher(nextJSP);
		// // dispatcher.forward(request,response);
		// response.setContentType("text/html");// from response, set content
		// type
		// PrintWriter out = response.getWriter();// from response, get output
		// writer
		// out.write("aaaa" + username);
		// out.close();

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}

}
